package com.sgb.kjwl.view.widget.transport;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;

import androidx.annotation.IntRange;
import androidx.databinding.DataBindingUtil;

import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.AppOfferStaticsDialogLayoutBinding;
import com.sgb.kjwl.model.entity.transport.OfferStatisticsEntity;

/**
 * Describe:    报价统计弹窗
 * Author:  yangLei
 * Date:    2022/1/4
 */
public class OfferStatisticsDialog extends Dialog {

    //0——普通货源   1——竞价货源
    private int type;
    private AppOfferStaticsDialogLayoutBinding mBinding;
    private OfferStatisticsEntity statisticsEntity;

    private OfferStatisticsDialog(Context context, int windowType) {
        super(context, R.style.app_transparent_dialog);
        this.type = windowType;
    }

    public static OfferStatisticsDialog newInstance(Context context, @IntRange(from = 0, to = 1) int windowType) {
        return new OfferStatisticsDialog(context, windowType);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mBinding = DataBindingUtil.inflate(LayoutInflater.from(getContext()), R.layout.app_offer_statics_dialog_layout, null, false);
        setContentView(mBinding.getRoot());
        initViews();
        setDataInfo();
    }

    private void initViews() {
//        mBinding.iconCar.setImageResource(type == 0 ? R.drawable.icon_quote_car_gray : R.drawable.icon_order_car_gray);
//        mBinding.iconCompany.setImageResource(type == 0 ? R.drawable.icon_quote_company_gray : R.drawable.icon_order_company_gray);
//        mBinding.iconTeam.setImageResource(type == 0 ? R.drawable.icon_quote_team_gray : R.drawable.icon_order_team_gray);
        mBinding.offerType.setText(String.format("货主意向运费%s", type == 0 ? "总价Y:" : "单价P:"));
        mBinding.tvExplain1.setText(String.format("报价高于%s以内", type == 0 ? "Y10%" : "P10%"));
        mBinding.tvExplain2.setText(String.format("报价高于%s以上", type == 0 ? "Y10%" : "P10%"));
        mBinding.tvExplain3.setText(String.format("报价低于%s以内", type == 0 ? "Y10%" : "P10%"));
        mBinding.tvExplain4.setText(String.format("报价低于%s以上", type == 0 ? "Y10%" : "P10%"));
        mBinding.tvExplain5.setText(String.format("报价等于%s", type == 0 ? "Y" : "P"));

        mBinding.closeBtn.setOnClickListener(v -> OfferStatisticsDialog.this.dismiss());
        setCanceledOnTouchOutside(false);
    }

    /**
     * 设置统计信息
     *
     * @param en
     */
    public void setStatisticsEntity(OfferStatisticsEntity en) {
        if (en == null)
            return;
        this.statisticsEntity = en;
        setDataInfo();
    }

    private void setDataInfo() {
        if (mBinding != null && statisticsEntity != null) {
            String offerStr = !TextUtils.isEmpty(statisticsEntity.getPriceStr()) ? statisticsEntity.getPriceStr() : "";
            mBinding.priceTv.setText(offerStr);
            mBinding.tvNum1.setText(offerStr.equals("电议") ? "--" : statisticsEntity.getExceedTenPercentWithinNum() + "");
            mBinding.tvNum2.setText(offerStr.equals("电议") ? "--" : statisticsEntity.getExceedTenPercentExceptNum() + "");
            mBinding.tvNum3.setText(offerStr.equals("电议") ? "--" : statisticsEntity.getUnderTenPercentWithinNum() + "");
            mBinding.tvNum4.setText(offerStr.equals("电议") ? "--" : statisticsEntity.getUnderTenPercentExceptNum() + "");
            mBinding.tvNum5.setText(offerStr.equals("电议") ? "--" : statisticsEntity.getEqualIntentionNum() + "");
            mBinding.tvNum6.setText(statisticsEntity.getTradedNum() + "");
        }
    }
}
